<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 14-5-23
 * Time: 下午11:26
 */

namespace builder\parts;

use ulue\web\Controller;
use Ulue;
use Ioc;
use builder\helpers\BuilderSidebar;

class BaseController extends Controller
{
    // public $layout = '@system/';

	static private $_verfiy_times=null;

	public $loginID = null;

	public function init()
	{
		$this->layout = Ioc::get('app.module')->path . '/resources/layouts/main.php';
	}

	public function beforeExecute()
	{
		// return $this->verify();
		return true;
	}

	public function verify()
	{
		//phpinfo();
		$env 	= Ioc::get('app.env');
		$clientIp 	= $env->server['addr'];

		$moduleOptions = Ulue::$app->get('modules.builder.options');
		$allowIps = !empty($moduleOptions['ip_filter']) ? (array)$moduleOptions['ip_filter'] : array();

		// md($ip,$moduleAllowIps,$allowIps);
		//允许访问的 ip 段
		if ( in_array($ip, $allowIps) )
		{
			// 已经登陆模块
			if ( $getS = Ioc::getSession()->get('gaa_verify') )
			{
				$default = encryption(Ulue::$app->get('visit_gaa_pwd'),1,Ulue::$app->get('session_salt_const'));
				if ( $default == $getS ) return true;
			}
			//首次访问模块
			if (IS_POST && IX('post.password') == Ulue::$app->get('visit_gaa_pwd'))
			{
				$this->loginID = Ioc::getSession()->set('gaa_verify',IX('post.password'));
				return true;
			} else
			{
				return $this->showPartial('builder/visit_form');
			}
		}
		else
		{
			// redirect(_APP_);
			$this->errorJump(_APP_,'访问错误！将跳转到首页',5);
			die;
		}

	}


}